package net.jitc.registers;

import java.util.Scanner;

/**
 * @Author admin
 * @Date 2019/4/2 14:02
 */
public class UserTest {
    static Scanner scannerInt = new Scanner(System.in);
    static Scanner scannerString = new Scanner(System.in);
    static UserDaoimp userDaoimp = new UserDaoimp();

    public static void main(String[] args) {
        while (true) {
            System.out.println("------欢迎光临------");
            System.out.println("1、注册");
            System.out.println("2、登录");
            System.out.println("3、搜索");
            System.out.println("4、查看");
            System.out.println("5、退出");
            System.out.println("请输入你的选择：");
            int choose = scannerInt.nextInt();
            switch (choose) {
                case 1:
                    registUr();
                    break;
                case 2:
                    loginUr();
                    break;
                case 3:
                    searchUr();
                    break;
                case 4:
                    checkAllUr();
                    break;
                case 5:
                    System.out.println("------欢迎下次光临------");
                    System.exit(0);
                default:
                    System.out.println("输入有误，请重新输入");
                    break;
            }
        }
    }


    private static void registUr() {
        System.out.println("------注册界面------");
        System.out.println("请输入姓名：");
        String name = scannerString.nextLine();
        System.out.println("请输入密码：");
        String password = scannerString.nextLine();
        System.out.println("请输入邮箱：");
        String email = scannerString.nextLine();
        User user = new User(name, password, email);
        userDaoimp.rgister(user);
    }

    private static void loginUr() {
        System.out.println("------登录界面------");
        System.out.println("请输入姓名：");
        String name = scannerString.nextLine();
        System.out.println("请输入密码：");
        String password = scannerString.nextLine();
        userDaoimp.login(name,password);
        boolean result=userDaoimp.login(name,password);
        if (result){
            System.out.println("登录成功！");
        }else {
            System.out.println("登录失败，账号或密码不准确！");
        }
    }

    private static void searchUr() {
        System.out.println("------搜索界面------");
        System.out.println("请输入姓名：");
        String name = scannerString.nextLine();
        userDaoimp.search(name);
    }

    private static void checkAllUr() {
        System.out.println("------查看界面------");
        System.out.println("");
        userDaoimp.checkAll();
    }
}
